package com.tdam2013.grupo07.networking;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import com.tdam2013.grupo07.Contactos;
import com.tdam2013.grupo07.R;

public class NotificationHandler implements NetworkingSubscriber, SendMessageEventObserver {

	private NotificationManager nManager;
	private Context context;
	private static final int NOTIFICACION_ID = 1;
	
	public NotificationHandler(NotificationManager nManager, Context context) {
		this.nManager = nManager;
		this.context = context;
	}

	public NotificationManager getnManager() {
		return nManager;
	}

	public void setnManager(NotificationManager nManager) {
		this.nManager = nManager;
	}

	@Override
	public void onReceiveMessage() {
		// TODO Auto-generated method stub
		
	}

	@SuppressWarnings("deprecation")
	@Override
	public void updateSendMessage(SendMessageResponse response) {
		int icon = R.drawable.logo7app2_32x32;
		CharSequence tickerText;
		long when = System.currentTimeMillis();
		
		Intent notificationIntent = new Intent(context, Contactos.class);
		PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
		CharSequence contentTitle = "Titulo";
		CharSequence contentText = "Contenido";
		
		if(response.isSuccess())
		{
			tickerText = context.getResources().getText(R.string.correcto_envio_mensaje_titulo);
			contentTitle = context.getResources().getText(R.string.correcto_envio_mensaje_titulo);
			contentText = context.getResources().getText(R.string.correcto_envio_mensaje_descripcion);
		}
		else
		{
			tickerText = context.getResources().getText(R.string.error_envio_mensaje_titulo);
			contentTitle = context.getResources().getText(R.string.error_envio_mensaje_titulo);
			contentText = context.getResources().getText(R.string.error_envio_mensaje_descripcion);
		}		
		
		Notification notification = new Notification(icon, tickerText, when);

		notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
		
		nManager.notify(NOTIFICACION_ID, notification);

		
	}

}
